﻿using System;
using System.Collections.Generic;
using System.Text;
using AMS.DataAccess.Interfaces;
using AMS.DataAccess.BO;
using AMS.DataAccess.Common;
using System.Data;

namespace AMS.DataAccess.Sql
{
    public class ProvinceCityManager : IProvinceCityManager
    {
        #region IProvinceCityManager Members

        public List<ProvinceCityInfo> GetCitiesByProvince(CallContext callContext, string provinceId)
        {
            string sql = string.Format("select dID, dName from TD_City where dProvinceID='{0}' order by dName ASC", provinceId);
            var ds = SqlDBHelper.Query(sql);

            var list = BusinessObjectMapping.DataTableToBOList<ProvinceCityInfo>(ds.Tables[0]);
            return list;
        }

        #endregion

        public List<ProvinceCityInfo> GetProvinces(CallContext context)
        {
            string sql = "SELECT DISTINCT dProvinceID, dProvinceName FROM TD_City ORDER BY dProvinceName ASC";
            var ds = SqlDBHelper.Query(sql);
            var list = BusinessObjectMapping.DataTableToBOList<ProvinceCityInfo>(ds.Tables[0]);
            return list;
        }

        public void AddProvince(CallContext context, ProvinceCityInfo pcInfo)
        {
            SqlInsert sqlInsert = new SqlInsert("TD_City");
            sqlInsert.AddBusinessObject(pcInfo);
            string sql = sqlInsert.ToString();
            SqlDBHelper.ExecuteSql(sql);
        }
    }
}
